/**   
 * @Title: ConListAdapter.java 
 * @Package com.cdtv.home.adapter 
 * @Description: 
 * @author zhuw
 * @date 2012-7-18 下午3:27:20 
 */
package com.adpter;

import java.util.List;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.ocean.util.common.StringUtil;
import com.common.method.CommonData;
import com.common.method.FromFlag;
import com.common.method.ServerPath;
import com.matang.R;
import com.modle.GiftStruct;
import com.view.GiftHoriView;

/**
 * 
 * @ClassName:GiftListAdapter
 * @Description:TODO
 * @author zhuw
 * @date 2013-7-24 上午11:29:54
 */
public class GiftListAdapter extends CusBaseAdapter {
	private List<GiftStruct> list;
	private Context context;

	/**
	 * @param list
	 * @param context
	 */
	public GiftListAdapter(List<GiftStruct> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolder vh = null;
		if (view == null) {
			view = LayoutInflater.from(context).inflate(
					R.layout.list_item_gift, null);
			vh = new ViewHolder();
			vh.thumbIv = (ImageView) view.findViewById(R.id.thumb_iv);
			vh.nameTv = (TextView) view.findViewById(R.id.name_tv);
			vh.giftIv = (ImageView) view.findViewById(R.id.giftIv);
			vh.numTv = (TextView) view.findViewById(R.id.numTv);
			vh.msgTv = (TextView) view.findViewById(R.id.msg_tv);
			view.setTag(vh);
		} else {
			vh = (ViewHolder) view.getTag();

		}
	final	GiftStruct data=list.get(position);
		
		imageLoader.bind(vh.thumbIv,ServerPath.SERVER+data.userThumb, null,R.drawable.default_head);

		System.out.println("--------------data.giftType:"+data.giftType);
		if(!StringUtil.isNull(data.giftType)){
			if(CommonData.getGiftMap().containsKey(data.giftType)){
				
				vh.giftIv.setImageResource(CommonData.getGiftMap().get(data.giftType));
			}
		}
		vh.nameTv.setText(data.userName);
		vh.msgTv.setText(data.msg);
		vh.numTv.setText(data.giftNum+"");
	vh.thumbIv.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			Bundle b = new Bundle();
			b.putSerializable("fUserID", data.uID);
			b.putInt("FromFlag", FromFlag.USER_SIMPLEINFO_GIFT);
			//TranHelper.toAct(context, UserSimpleInfoActivity.class, b);		
			
		}
	});
		return view;
	}

	class ViewHolder {
		TextView nameTv,  msgTv,numTv;
		ImageView thumbIv,giftIv;
		GiftHoriView giftView;

	}

}
